<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>serialize方法说明</title>
</head>
<body>
	<form id="form">
		<input type="text" name="username">
		<input type="password" name="password">
		<input type="submit" value="提交">
	</form>
	<script src="/js/jquery.min.js"></script>
	<script type="text/javascript">
		$('#form').on('submit',function(){
			//将表单内容拼接成字符串类型的参数
			// var params = $('#form').serialize();
			// console.log(params);
			serializeObject($(this))
			return false;
		});

		//将表单中用户输入的内容转换为对象类型
		function serializeObject(obj) {
			var result = {};
			//[{name:'username',value:'输入的内容'},{name:'password',value:'123'}]
			//serializeArray
			var params = obj.serializeArray();
			//循环数组将数组转换为对象类型
			$.each(params,function (index,value) {
				result[value.name] = value.value;	
			  })
			 return result;
		  }
	</script>
</body>
</html>